package com.wyf.controller;

import com.wyf.exceptions.BusinessException;
import com.wyf.exceptions.ParamsException;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 全局异常处理方式三
 *
 */
public class BaseController {

    /**
     * 处理异常方法
     * @param request
     * @param response
     * @param e
     * @return
     */
    @ExceptionHandler
    public String exceptionResolver(HttpServletRequest request, HttpServletResponse response, Exception e) {
        request.setAttribute("ex", "这是第三种异常处理");
        // 判断异常类型
        if (e instanceof ParamsException) {
            return "params_error";
        } else if (e instanceof BusinessException) {
            return "business_error";
        }
        return "error";
    }
}
